package demo6;

import java.util.Stack;

//判断一个序列是否是另一个序列出栈的可能的序列
public class StackPush {
        public  boolean Isrule(int[] val1,int []val2){
            Stack<Integer> stack=new Stack<>();
            int j=0;
            for(int i=0;i<val1.length;i++){
                stack.push(val1[i]);
                while(j<val2.length&&!stack.empty()&&stack.peek()==val2[j]){
                    stack.pop();
                    j++;
                }
            }
            return stack.empty();
        }

}
